home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 October: Technology Seed / ADC Seed CD - October 1999.toast / FireWire / FireWire_2.1_SDK_DR3 / Source / SBP2 / FWSBP2DiskDriver / FWSBP2DiskDriver.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-17  |  8.1 KB  |  232 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        FWSBP2DiskDriver.h
  3.  
  4.     Contains:    Include file for sample SBP-2 disk driver
  5.  
  6.     Version:    1.0
  7.  
  8.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Clinton Bauder
  13.  
  14.         Other Contact:        Eric Anderson
  15.  
  16.         Technology:            FireWire
  17.  
  18.     Writers:
  19.  
  20.         (EA)    Eric Anderson (ewa)
  21.         (DCB)    Clinton Bauder
  22.  
  23.     Change History (most recent first):
  24.  
  25.       <FW22>     4/30/99    EA        Added fields to protect the LUN reset object from being used
  26.                                     when it is already in use.
  27.       <FW21>     4/29/99    DCB        Cleaned up a few variables to simplify and improve our reset and
  28.                                     reconnect handling.
  29.       <FW20>     4/29/99    EA        Add variables for restoring BUSY_TIMEOUT after a new login.
  30.       <FW19>     3/31/99    EA        Changed packet size from 256 to 1024.
  31.       <FW18>     3/27/99    EA        Add fields/enum for small-transfer double-buffer.
  32.       <FW17>      3/8/99    DCB        Get rid of unused variables, cleanup our login state variables
  33.                                     and add some constants for payload size and error recovery
  34.                                     control.
  35.       <FW16>      3/4/99    DCB        Support for write verification.
  36.       <FW15>      3/2/99    DCB        Put drive info in DrvSts2. Less of a hack this way, kinda sorta
  37.                                     (the whole structure is a hack but at least its not MY hack.)
  38.       <FW14>     2/22/99    EA        Removed registrationRef; nobody was using it.
  39.       <FW13>     2/16/99    DCB        Add better support for 2 macs-1 drive, that is do the right
  40.                                     thing if we fail a login.
  41.       <FW12>     2/15/99    DCB        Cleanup for Eric's notification changes.
  42.       <FW11>     1/25/99    DCB        Even yet more re-plug stuff.
  43.       <FW10>     1/21/99    DCB        Even more stuff for hot-plugging.
  44.        <FW9>     1/19/99    DCB        More stuff for unplugging/repluggin.
  45.        <FW8>     1/15/99    DCB        Stuff for unplugging drives.
  46.        <FW7>    12/29/98    DCB        Added a buffer for double buffering. Could get quite large if
  47.                                     kMaxTransfer size is large enough.
  48.        <FW6>    12/23/98    DCB        Don't do ReqSense anymore as some drives don't like this. Back
  49.                                     to straight retries for error checking. Also fixed up the
  50.                                     Symbios ROM flash code.
  51.        <FW5>    12/18/98    DCB        Change use of login var.
  52.        <FW4>    12/18/98    DCB        Fixed Comment header. Time to go home...
  53.        <FW3>    12/18/98    DCB        A few changes for clear box support.
  54.        <FW2>    11/17/98    DCB        Misc Cleanup.
  55.        <FW1>    11/17/98    DCB        first checked in
  56.        <FW2>     9/20/98    EA        Filled in header comments.
  57.        <FW1>     9/20/98    EA        first checked in
  58. */
  59.  
  60.  
  61. #ifndef __FWSBP2DRIVER__
  62. #define __FWSBP2DRIVER__
  63.  
  64. #ifndef __TYPES__
  65. #include <Types.h>
  66. #endif
  67. #ifndef __FIREWIRE__
  68. #include <FireWire.h>
  69. #endif
  70.  
  71. #ifdef __cplusplus
  72. extern "C" {
  73. #endif
  74.  
  75. #if PRAGMA_IMPORT_SUPPORTED
  76. #pragma import on
  77. #endif
  78.  
  79. #if PRAGMA_ALIGN_SUPPORTED
  80. #pragma options align=mac68k
  81. #endif
  82.  
  83. // Turn this on to read back all writes to compare the data. Uses about 125K of RAM for a max transfer of 250 blocks
  84. #define VerifyWrites 0
  85.  
  86. // Turn this on if your device doesn't handle fetch agent resets properly
  87. #define needLUNReset 1
  88.  
  89. enum {
  90.  
  91.     kBlockSize = 512,
  92.     kMaxTransfer = 250,                // Set to 1 for clear box drive
  93.     
  94.     kDiskDriverPayloadSize = 1024,     // Packet size.  1024 is safe with FireWire 2.1 and setting the retry flag
  95.     
  96.     kSmallDoubleBufferSize = 8192,    // Any request of this size or smaller will be double buffered.
  97.                                     // This value is just a guess.  It helps for single-block IO.
  98.     
  99.     kAsyncORB = 0,
  100.     kImmedORB = 2,
  101.     kTotalORBs = 3
  102.     
  103. };
  104.  
  105. struct FWSBP2DriverDataStruct
  106. {
  107.     // Important! Next two items need to be at the front of this structure in order to be aligned properly!
  108.     
  109.     UInt8                        dataBuffer[kMaxTransfer << 9];        // For double buffering. !!! Could get real big!
  110.  
  111. #if VerifyWrites
  112.     UInt8                        verifyBuffer[kMaxTransfer << 9];    // For double buffering. !!! Could get real big!
  113.     UInt8                        * whatWasWritten;
  114. #endif
  115.  
  116.     FWDriverID                    fwDriverID;                // Our driver ID.
  117.     CSRROMEntryID                csrUnitID;                // Out unit directory ID.
  118.     RegEntryID                    pRegEntryID;
  119.     
  120.     SInt16                        drvrRefNum;
  121.     Boolean                        gotEject;                // True if we got ejected/offlined at some point...
  122.     Boolean                        returnDiskErr;            // True if user canceled the replug dialog
  123.  
  124.     FWCommandObjectID            loginCommandID;            // Login command object
  125.  
  126.     Boolean                        loggedIn;                // True if we are logged in
  127.     Boolean                        wasLoggedIn;            // true if at some point we successfully logged into the drive.
  128.     Boolean                        doubleBuffer;            // True if we are double buffering this transfer.
  129.     Boolean                        wait4Replug;            // True if we're waiting for a re-plug.
  130.                                                         // Don't bother with reset notification or other nonsense
  131.                                                         // until FSL thinks we're back.
  132.                                                         
  133.     volatile UInt32                loginObjBusy;            // non - zero if login object is in use
  134.     
  135.     Boolean                     reLogin;                // True if after a logout we want to try and login again
  136.     Boolean                        reconnecting;            // True if we are trying to reconnect.
  137.     Boolean                        unused[2];                // Pad to longword
  138.     
  139.     SInt32                         loginReqs;                // Number of times an event occured triggering a login request
  140.  
  141.     FWAddress                    fetchAgent;                // From login response.
  142.  
  143.     FWCommandObjectID            orbID[4];                // ORB command objects 2 for Async, 1 for Immediate, 1 for other stuff
  144.     UInt32                        currentORB;                // 1 or 0 depending on which one we're using
  145.     FWCommandObjectID            fwAGENT_RESET_ID;        // Command object for FWWrite
  146.     FWCommandObjectID            fwLUNReset_ID;            // Command object for resetting LUN with kSBP2LogicalUnitReset
  147.     FWCommandObjectID            fwReconnectID;            // Command object for reconnecting after device goes away
  148.     FWCommandObjectID            fwReplugID;                // Command object for requesting a drive re-plug
  149.     
  150.     volatile OSStatus            immedStatus;            // Status of immediate command                            
  151.     volatile OSStatus            utilStatus;                // Status of utility command                            
  152.     
  153.     UInt32                        xferLeft;                // Used for really BIG transfers that can't
  154.                                                         // be completed with 1 10 byte command
  155.     UInt32                        next_block;                // next block to xfer to 
  156.     Ptr                            next_buffer;            // next chunk of buffer
  157.     
  158.     Boolean                        ioPending;                // Used for error handling
  159.     Boolean                        isWrite;                // Used for retries and big commands
  160.     Boolean                        queuedDQEl;                // True if we called AddDrive.
  161.     Boolean                        needsVerify;
  162.     UInt32                        retriesLeft;            // ""
  163.     UInt32                        count;                    // ""
  164.     UInt32                        sector;                    // ""
  165.     Ptr                            buffer;                    // ""
  166.     
  167.     FWAddress                    buffers[1];                // ""
  168.     UInt32                        lengths[1];                // ""
  169.     UInt8                        command[12];            // ""
  170.     UInt8                        aBuffer[12];            // Used for ReqSense
  171.     
  172.     IOParamPtr                     ioPB;                    // Remember the current parameter block and dce for
  173.     DCtlEntry                    * dce;                    // the benefit of the async callback routine
  174.     IOCommandID                    ioCommandID;            // Remember command ID as well
  175.     
  176.     UInt32                        totalBlocks;            // Size of the disk in blocks
  177.     
  178.     Ptr                            smallBuffer;            // Buffer for double-buffering small requests
  179.     FWCommandObjectID            smallBufferORB;            // ORB reserved for small requests (static prepmemio)
  180.     Boolean                        useSmallBuffer;            // Small buffer is in use
  181.     Boolean                        immediate;                // Synchronous call, don't copy twice (zzz clean up)
  182.     Boolean                        lunResetBusy;            // fwLUNReset_ID is in use
  183.     Boolean                        lunResetAgain;            // ... and when done, we need to do it again
  184.  
  185.     FWCommandObjectID            busyTimeoutCommandID;    // Command object to set the BUSY_TIMEOUT register
  186.     UInt32                        busyTimeout;            // Value to set each time
  187.     Boolean                        busyTimeoutCommandBusy;    // Flag set if command object in use
  188.     Boolean                        busyTimeoutAgain;        // Flag set if we should do it again
  189.     Boolean                        unused3[2];                // Padding
  190.  
  191.     UInt32                        bitBucket;                // place to throw away data.                
  192.  
  193.     // DrvSts2 is a particularly gross legacy structure. Using it is probably cleaner than trying
  194.     // to duplicate the structure inside of our own globals although it introduces other inconveniences
  195.     // when trying to use some of the fields within.
  196.     DrvSts2                        driveStatus;
  197.         
  198. };
  199. typedef struct FWSBP2DriverDataStruct
  200.                                 FWSBP2DriverData,
  201.                                 *FWSBP2DriverDataPtr;
  202.                                 
  203. struct sbpStatusBlockStruct
  204. {
  205.     UInt8                        stSrcRespLen;
  206.     UInt8                        stSBPStatus;
  207.     UInt16                        stOrbOffsetHi;
  208.     UInt32                        stOrbOffsetLo;
  209.     UInt8                        stStatus;
  210.     UInt8                        stKey;
  211.     UInt8                        stCode;
  212.     UInt8                        stQualifier;
  213. };
  214. typedef struct sbpStatusBlockStruct
  215.                                 sbpStatusBlock,
  216.                                 *sbpStatusBlockPtr;
  217.  
  218.  
  219. #if PRAGMA_ALIGN_SUPPORTED
  220. #pragma options align=reset
  221. #endif
  222.  
  223. #if PRAGMA_IMPORT_SUPPORTED
  224. #pragma import off
  225. #endif
  226.  
  227. #ifdef __cplusplus
  228. }
  229. #endif
  230.  
  231. #endif /* __FWSBP2DRIVER__ */
  232.